﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Extjs_ReGSharp.Sorting
{
	internal class SortingBehaviourQueueOrginizer<T>
	{
		#region Data Memebers

		private List<ISortingBehaviourFactory<T>> m_SortingBehavioursFactorys;

		#endregion

		#region Consts

		internal SortingBehaviourQueueOrginizer(List<ISortingBehaviourFactory<T>> sortingBehaviourFactoryList)
		{
			m_SortingBehavioursFactorys = new List<ISortingBehaviourFactory<T>>();

			if (sortingBehaviourFactoryList != null)
			{
				m_SortingBehavioursFactorys.AddRange(sortingBehaviourFactoryList);
			}

			m_SortingBehavioursFactorys.Add(new DefaultBehaviourFactory<T>());
		}

		#endregion

		#region Public Methods

		internal ISortingBehaviour<T> GetSortingBehaviour(string field)
		{
			foreach (ISortingBehaviourFactory<T> factory in m_SortingBehavioursFactorys)
			{
				ISortingBehaviour<T> sortingBehaviour = factory.CreateSortingBehaviour(field);

				if (sortingBehaviour != null)
				{
					return sortingBehaviour;
				}
			}

			return null;
		}

		#endregion
	}
}
